﻿//********************************************************************************//
//创建日期：<创建日期，2016-4-13>
//页面创建：<孙雪婷，sunxueting@shanghai3h.com>
//后台逻辑：郭登杰 2016-06-12
//功能说明：退款确认
//********************************************************************************//
using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI.WebControls;
using BLL.Access;
using BLL;
using Web.Class;
using Entity;
using DevExpress.Web;

namespace Web.Pages.YongShui._6.ZhangWuGL
{
    public partial class TuiKuanQR : BasePage
    {
        #region 属性

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据库操作对象
        /// </summary>
        SpHelper _sphelper = new SpHelper();

        /// <summary>
        /// 来函信息数据处理
        /// </summary>
        YS_LH_LAIHANXXProcess _YS_LH_LAIHANXXBLL = new YS_LH_LAIHANXXProcess();

        #endregion

        #region 事件

        /// <summary>
        /// 加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                LoadData(true);
            }
        }

        protected void btnCanXun_Click(object sender, EventArgs e)
        {

        }

        protected void btnTuiHui_Click(object sender, EventArgs e)
        {

        }

        protected void btnQueRen_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 回调响应
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            //判断是否有勾选
            List<YS_LH_TUIKUANXX> list = this.SelectedTuiKuanXXList();
            if (list.Count == 0)
            {
                e.Result = e.Parameter + "|-1|" + "未选择要操作的记录。";
                return;
            }
            if (e.Parameter == "tuihui")
            {
                //将对应来函状态更新为流程中,步骤更新到登记
                for (int i = 0; i < list.Count; i++)
                {
                    this._YS_LH_LAIHANXXBLL.UpdateYS_LH_LAIHANXXesDynamic("I_LIUCHENGZT=0,I_LIUCHENGBH=" + (int)eLaiHanLCBH.预登记 + ",S_CAOZUOR=" + LoginInfo.CurrentUser.Account + ",D_CAOZUOSJ=to_date('" + BusinessTool.GetDataBaseDateTime().ToString("yyyy-MM-dd HH:mm:ss") + "','yyyy-MM-dd HH24:mm:ss')", "S_LAIHANBH=" + list[i] + " AND I_LAIHANLX=" + (int)eLaiHanLX.退款);
                }
                e.Result = e.Parameter + "|0|" + "操作成功。";
                return;
            }
            else if (e.Parameter == "queren")
            {
                string rsno="-1";
                string rsmsg="";
                for (int i = 0; i < list.Count; i++)
                {
                    this._sphelper.P_YSZW_TUIKUANQR(list[i].S_LAIHANBH,(int)list[i].I_TUIKUANLX,(int)list[i].I_FEIYONGBH,Convert.ToDecimal(list[i].N_TUIKUANJE),list[i].S_TUIKUANFPHM,BusinessTool.GetZWYM(),LoginInfo.CurrentUser.UserID,out rsno,out rsmsg);
                }
                e.Result = e.Parameter + "|0|" + "操作成功。";
            }
        }

        /// <summary>
        /// 前台验证后实际执行后台操作
        /// </summary>
        protected void btnActPerform_Click(object sender, EventArgs e)
        {
            LoadData(true);
        }

        #endregion

        #region 方法

        /// <summary>
        /// 配置控件
        /// </summary>
        public void InitControl()
        {
            //加载退款类型
            WordsManager manger = new WordsManager();
            PageTools.BindComboBox(this.cmbTuiKuanLX, manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.退款类型, "_"), "");
            this.cmbTuiKuanLX.SelectedIndex = 0;
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="reget">是否重新获取</param>
        private void LoadData(bool reget)
        {
            if (reget)
            {
                this.dtSource = this._sphelper.P_YSZW_TUIKUANQRLIST(this.txtYongHuH.Text.Trim() == "" ? null : this.txtYongHuH.Text.Trim(),
                                                                    this.txtYongHuM.Text.Trim() == "" ? null : this.txtYongHuM.Text.Trim(),
                                                                    this.txtYM.Text.Trim() == "" ? null : (int?)int.Parse(this.txtYM.Text.Trim()),
                                                                    this.cmbTuiKuanLX.Text == "" ? null : (int?)Convert.ToInt32(this.cmbTuiKuanLX.Value),
                                                                    this.txtLaiHanBH.Text.Trim() == "" ? null : this.txtLaiHanBH.Text.Trim()).Tables[0];
            }
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
            this.Binding();
        }

        /// <summary>
        /// 获取选中退款信息列表
        /// </summary>
        private List<YS_LH_TUIKUANXX> SelectedTuiKuanXXList()
        {
            List<YS_LH_TUIKUANXX> list = new List<YS_LH_TUIKUANXX>();
            for (int i = 0; i < this.gvList.VisibleRowCount; i++)
            {
                ASPxCheckBox ck = (ASPxCheckBox)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "cid");
                if (ck.Checked)
                {
                    YS_LH_TUIKUANXX obj = new YS_LH_TUIKUANXX();
                    HiddenField hfLaiHanBH = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "hfLaiHanBH");
                    HiddenField hfTuiKuanLX = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "hfTuiKuanLX");
                    HiddenField hfFeiYongBH = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "hfFeiYongBH");
                    HiddenField hfTuiKuanJE = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "hfTuiKuanJE");
                    obj.S_LAIHANBH = hfLaiHanBH.Value;
                    obj.I_TUIKUANLX = int.Parse(hfTuiKuanLX.Value);
                    obj.I_FEIYONGBH = int.Parse(hfFeiYongBH.Value);
                    obj.N_TUIKUANJE = double.Parse(hfTuiKuanJE.Value);
                    list.Add(obj);
                }
            }
            return list;
        }

        /// <summary>
        /// 绑定设置
        /// </summary>
        private void Binding()
        {
            for (int i = 0; i < this.gvList.VisibleRowCount; i++)
            {
                ASPxCheckBox ck = (ASPxCheckBox)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "cid");
                HiddenField hfTuiKuanZT = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "hfTuiKuanZT");
                ck.Visible = hfTuiKuanZT.Value == "0";
            }
        }

        #endregion
    }
}